package com.huangpuweb.api.service.imp;

import com.huangpuweb.api.model.HpScenicRealTime;
import com.huangpuweb.api.service.SyncScenicSpotService;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @author rufeng
 * @date 2021/1/29 13:33
 */
@Service
public class SyncScenicSpotServiceImpl extends BaseScenicSpotServiceImp implements SyncScenicSpotService {

    @Override
    public HpScenicRealTime getTodayMax(String today, String spotCodeArr) {
        String sql="select *  from hp_spot_realtime where spotid=? and createTime >=? order by realtimeNumber desc limit 1";
        return getEntry(sql, new RowMapper<HpScenicRealTime>() {
            @Override
            public HpScenicRealTime mapRow(ResultSet resultSet, int i) throws SQLException {
                HpScenicRealTime hp=new HpScenicRealTime();
                hp.setSpotid(resultSet.getString("spotid"))
                        .setTotalnumber(resultSet.getString("totalnumber"))
                        .setRealtimenumber(resultSet.getString("realtimenumber"))
                        .setCreateTime(resultSet.getString("createTime"));
                return hp;
            }
        },new Object[]{spotCodeArr,today});
    }


    @Override
    public List<HpScenicRealTime> getAllSpotDay(String yuyuan, String todayZero, String today23) {
        String sql = "select * from hp_spot_realtime where spotid=? and createTime <=? and createTime >=? ORDER BY createTime ASC";

        return getEntryList(sql, new RowMapper<HpScenicRealTime>() {
            @Override
            public HpScenicRealTime mapRow(ResultSet resultSet, int i) throws SQLException {
                HpScenicRealTime hp=new HpScenicRealTime();
                hp.setSpotid(resultSet.getString("spotid"))
                        .setTotalnumber(resultSet.getString("totalnumber"))
                        .setRealtimenumber(resultSet.getString("realtimenumber"))
                        .setCreateTime(resultSet.getString("createTime"));
                return hp;
            }
        },new Object[]{yuyuan,todayZero,today23});
    }

    @Override
    public HpScenicRealTime getAllSpot(String spotCodeArr) {
        String sql="select spotid,totalnumber,realtimenumber,createTime from hp_spot_realtime where spotid=? order by createTime desc limit 1 ";
        return getEntry(sql, new RowMapper<HpScenicRealTime>() {
            @Override
            public HpScenicRealTime mapRow(ResultSet resultSet, int i) throws SQLException {
                HpScenicRealTime hp=new HpScenicRealTime();
                hp.setSpotid(resultSet.getString("spotid"))
                        .setTotalnumber(resultSet.getString("totalnumber"))
                        .setRealtimenumber(resultSet.getString("realtimenumber"))
                        .setCreateTime(resultSet.getString("createTime"));
                return hp;
            }
        },new Object[]{spotCodeArr});
    }

    @Override
    public String findScenicSpot(String uuid) {
        String sql="select uuid from hp_scenic_number where uuid=? ";
        return queryString(sql,new Object[]{uuid});
    }
    @Override
    public String findCurrentquery(String spotCode) {
        String sql = "select uuid from hp_scenic_number where spotcode=? ";
        return queryString(sql, new Object[]{spotCode});
    }



    @Override
    public HpScenicRealTime getSpotDataByHour(String spotCode, String date) {
        String sql = "select * from hp_spot_realtime where spotid = ? and createTime <= ? order by createTime desc limit 1";
        return getEntry(sql, new RowMapper<HpScenicRealTime>() {
            @Override
            public HpScenicRealTime mapRow(ResultSet resultSet, int i) throws SQLException {
                HpScenicRealTime hp=new HpScenicRealTime();
                hp.setSpotid(resultSet.getString("spotid"))
                        .setTotalnumber(resultSet.getString("totalnumber"))
                        .setRealtimenumber(resultSet.getString("realtimenumber"))
                        .setCreateTime(resultSet.getString("createTime"));
                return hp;
            }
        },new Object[]{spotCode,date});
    }

    @Override
    public List<HpScenicRealTime> getSpotDataBySpotCodePastHour(String spotCode, String pastHour) {
        String sql = "select * from hp_spot_realtime where spotid =? and createTime like ?";
        return getEntryList(sql, new RowMapper<HpScenicRealTime>() {
            @Override
            public HpScenicRealTime mapRow(ResultSet resultSet, int i) throws SQLException {
                HpScenicRealTime hp=new HpScenicRealTime();
                hp.setSpotid(resultSet.getString("spotid"))
                        .setTotalnumber(resultSet.getString("totalnumber"))
                        .setRealtimenumber(resultSet.getString("realtimenumber"))
                        .setCreateTime(resultSet.getString("createTime"));
                return hp;
            }
        }, new Object[]{spotCode, pastHour + "%"});
    }


}
